package completablefuture;

import java.util.concurrent.CompletableFuture;

public class Test2 {
    public static void main(String[] args) {
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            MyUtil.sleep(1000);
            int i = 10 / 0;
            return "Hello";
        });
        // 正常执行完
        future.whenComplete((s, e) -> System.out.println("res: " + s + ", err: " + e));
         // 发生异常
        future.exceptionally(t -> {
            System.out.println("Exception occurred: " + t.getMessage());
            return "Error";
        });
        future.join();
    }
}
